<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义Promise</title>
</head>
<body>
    <script src="./02_Promise.js"></script>
    <!-- <script>
        const p = new Promise((resolve, reject)=>{
            resolve(11)
            // reject(22);
            setTimeout(() => {
                // resolve(1);
                // reject(2);          
            }, 10);
        });

        p.then(
            value=>{
                console.log('onResolved()1 ', value);
                throw 113
                return new Promise((resolve, reject)=>{
                    setTimeout(() => {
                        resolve(111)
                    }, 1000);
                });
             },
            reason =>{
                console.log('onRejected()1 ', reason)
                // throw 333
                return new Promise((resolve, reject)=>{
                    setTimeout(() => {

                    }, 1000);
                });
            }
        ).then(
            value=>{
                console.log('onResolved()2 ', value);
             },
            reason =>{
                console.log('onRejected()2 ', reason)
            }
        ) .catch(reason=>{
            console.log(reason)
        })

    </script> -->

    <script>

        const p1 = Promise.resolve(1);
        p1.then(value=>{console.log('p1 ', value)}).catch(reason=>{console.log(reason)})

        const p2 = Promise.resolve(Promise.resolve(2));
        p2.then(value => {console.log('p2', value)});

        const p3 = Promise.reject(3);
        p3.catch(reason => {console.log('p3', reason)});

        const p4 = Promise.resolve(Promise.reject(4));
        p4.then(null, reason=>{console.log('p4', reason)})


        const pAll = Promise.all([p1, p2, p3]);
        pAll.then(values=>{
            console.log('All Resolved ', values);
        },
        reason=>{
            console.log('All reject', reason)
        })


        const pRace = Promise.race([p3, p2, p1]);
        pRace.then(values=>{
            console.log('Race Resolved ', values);
        },
        reason=>{
            console.log('Race reject', reason)
        })

        Promise.resolveDelay(66, 1000).then(value=>{console.log(value)});
        Promise.rejectDelay(77, 1000).catch(reason => {console.log(reason)});
    </script>

</body>
</html>